<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/


Route::get('/', function () {
    return view('auth.login-admin');
});
Route::get('/guideline', function () {
    return view('guideline');
})->name('guideline');
Route::get('/about', function () {
    return view('about');
});

Route::get('/test', function () {
    return view('errors.403');
});


Route::get('/waiting', function () {
    return view('waiting');
})->name('waiting');

Route::group(['middleware' => 'auth.basic'], function () {
    Route::post('/user/updateCredentials', 'UsersController@updateCredentials');
    Route::post('/user/updateBasic', 'UsersController@updateBasic');
    Route::post('/profile', 'UsersController@update_avatar')->name('profile.update');
    Route::get('/profile', 'UsersController@profile')->name('profile.index');
});


Route::group(['middleware' => ['auth', 'perm.check']], function () {

    Route::get('/online', 'UsersController@online')->name('online.index');

    //宿舍信息
    Route::resource('dorms', 'DormsController');
    Route::get('dorms/order/sort', ['as' => 'dorms.order.sort', 'uses' => 'DormsController@orderSort']);
    Route::post('dorms/order/save', ['as' => 'dorms.order.save', 'uses' => 'DormsController@orderSave']);
    Route::resource('dorm-meters', 'DormMetersController');
    Route::resource('dorm-meter-adjusts', 'DormMeterAdjustsController');
    Route::resource('dorm-meter-records', 'DormMeterRecordsController');
    Route::post('set-water-meters/{id}', 'DormsController@setWaterMeter');
    Route::resource('meter-types', 'MeterTypesController');
    Route::resource('dorm-types', 'DormTypesController');
    Route::resource('buildings', 'BuildingsController');
    Route::get('buildings/order/sort', ['as' => 'buildings.order.sort', 'uses' => 'BuildingsController@orderSort']);
    Route::post('buildings/order/save', ['as' => 'buildings.order.save', 'uses' => 'BuildingsController@orderSave']);
    Route::post('buildings/{id}/gen_dorms', ['as' => 'buildings.gen_dorms', 'uses' => 'BuildingsController@genDorms']);
    Route::resource('companies', 'CompaniesController');

    //人员信息
    Route::resource('staffs', 'StaffController');
    Route::resource('families', 'FamiliesController');
    Route::resource('staff-dorm-adjusts', 'StaffDormAdjustsController');
    Route::get('staffs/{id}/dorm-arrange', ['as' => 'staffs.dormArrange', 'uses' => 'StaffController@dormArrange']);
    Route::resource('departments', 'DepartmentsController');
    Route::resource('staff-positions', 'StaffPositionsController');

    //费用信息
    Route::resource('fees', 'FeesController');
    Route::resource('periods', 'PeriodsController');
    Route::get('periods/{id}/not_rec', ['as' => 'periods.not_rec', 'uses' => 'PeriodsController@not_rec']);
    Route::post('/periods/{id}/calc', ['as' => 'periods.calc', 'uses' => 'PeriodsController@calc']);
    Route::post('/periods/{id}/un_verify', ['as' => 'periods.un_verify', 'uses' => 'PeriodsController@un_verify']);
    Route::resource('electric-fee-types', 'ElectricFeeTypesController');
    Route::resource('water-fee-types', 'WaterFeeTypesController');
    Route::resource('hot-water-fee-types', 'HotWaterFeeTypesController');
    Route::resource('manage-fee-types', 'ManageFeeTypesController');
    Route::resource('deposit-types', 'DepositTypesController');

    //用户管理
    Route::resource('users', 'UsersController');
    Route::resource('roles', 'RolesController');
    Route::resource('permissions', 'PermissionsController');
    Route::resource('permission-categories', 'PermissionCategoryController');
    Route::resource('staff-period-fees', 'StaffPeriodFeesController');
    Route::resource('staff-period-fee-details', 'StaffPeriodFeeDetailsController');
    Route::resource('deposits', 'DepositsController');

    //宿舍评分管理
    Route::resource('rating-categories', 'RatingCategoriesController');
    Route::resource('rating-subitems', 'RatingSubitemsController');
    Route::resource('dormitory-ratings', 'DormitoryRatingsController');
    Route::resource('dorm-rating-mains', 'DormRatingMainsController');
    Route::get('dorm-ratings-export/{period_id}', 'DormRatingMainsController@export')->name('dorm-ratings-export');
});

//NO permission check
Route::group(['middleware' => ['auth']], function () {
    Route::post('staffs/import/excel', 'StaffController@handleExcelImport');
    Route::get('staffs/download/excel', 'StaffController@handleTemplateDownload');

    Route::post('dormMeters/import/excel', 'DormMetersController@handleExcelImport');
    Route::get('dormMeters/download/excel', 'DormMetersController@handleTemplateDownload');

    Route::post('dormMeterRecords/import/excel', 'DormMeterRecordsController@handleExcelImport');
    Route::get('dormMeterRecords/download/excel', 'DormMeterRecordsController@handleTemplateDownload');
});


Route::get('/home', 'HomeController@index')->name('home');


Auth::routes();
